package com.example.smartcity_poverty.ui.AllService.Attorneys.fragment

import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.example.smartcity_poverty.App.Companion.getToken
import com.example.smartcity_poverty.App.Companion.url
import com.example.smartcity_poverty.R
import com.example.smartcity_poverty.logic.Repository.api
import com.example.smartcity_poverty.logic.Repository.coroutine
import com.example.smartcity_poverty.logic.util.Util.glide
import com.example.smartcity_poverty.logic.util.Util.show
import kotlinx.android.synthetic.main.fragment_attorneys_home.*
import kotlinx.coroutines.Dispatchers

/**
 *  律师咨询主页功能模块描述
 */
class AttorneysHomeFragment : Fragment() {
    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_attorneys_home, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        coroutine(Dispatchers.IO){
            api.getAttUserAll(getToken(), AttId).apply {
                if (this.code == 200){
                    activity?.runOnUiThread {
                        Log.d("Image", "onViewCreated: --> ${this.data?.certificateImgUrl}")
                        this.data?.let {
                            glide(url + it.certificateImgUrl, attListShowContent5)
                            attListShowContent1.text = "${it.eduInfo}"
                            attListShowContent2.text = "${it.workStartAt}"
                            attListShowContent3.text = "${it.licenseNo}"
                            attListShowContent4.text = "${it.baseInfo}"
                        }
                    }
                }else activity?.runOnUiThread { this.msg?.show() }
            }
        }
    }

    companion object{
        var AttId = 0
    }
}